package com.cjg.netCode;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class serverNet {
    public static void main(String[] args) {
        //服务端新建一个地址 ,和默认本地的ip
        try {
            ServerSocket serverSocket = new ServerSocket(8888);
            Socket clientSocket = serverSocket.accept();
            InputStream is = clientSocket.getInputStream();
            //接收消息

            //创建缓冲区
          //存在乱码问题 超出后
         byte[] bytes = new byte[1000];
            int lent;
            while ((lent=is.read(bytes))!=-1){
                String s = new String(bytes, 0, lent);
                System.out.println(s);
            }
        /*    //需要一个管道流   时代变了 管道流产生Connection reset 错误  爷青结
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] bytes = new byte[1023];
            int lent;
           while ((lent=is.read(bytes))!=-1){
               baos.write(bytes,0,lent);
           }
            System.out.println(baos.toString());*/



        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
